/**
 * 系统管理 菜单管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 主体内容 -->
    <el-row>
      <!-- title -->
      <div class="modt-box">用户管理</div>
      <el-col :span="4"> </el-col>
      <el-col :span="6">
        <div class="mod-btnbox">
          <el-button size="small"
                     type="primary">全部展开</el-button>
          <el-button size="small"
                     type="primary">全部压缩</el-button>
        </div>
        <!-- <el-tree class="treeclass"
                 ref="tree"
                 :data="treeData"
                 default-expand-all=""
                 :props="defaultProps"
                 @node-click="nodeclick"
                 @check-change="handleClick"
                 check-strictly
                 node-key="id"
                 show-checkbox>
                 </el-tree> -->

        <treeMenu @callfather="callfather"
                  :isalert="isalert"
                  :isShowCheckbox="false" />
      </el-col>

      <el-col :span="18">
        <div class="mod-btnbox">
          <el-button size="small"
                     type="primary"
                     icon="el-icon-plus">添加</el-button>
        </div>
        <el-form ref="form"
                 :model="form"
                 label-width="80px"
                 :rules="rules">
          <el-form-item label="菜单id"
                        prop="menuid">
            <el-input size="small"
                      v-model="form.menuid"
                      :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="菜单名称"
                        prop="menuname">
            <el-input size="small"
                      v-model="form.menuname"></el-input>
          </el-form-item>
          <el-form-item label="图标"
                        prop="icon">
            <el-input size="small"
                      v-model="form.icon"></el-input>
          </el-form-item>
          <el-form-item label="URL"
                        prop="url">
            <el-input size="small"
                      v-model="form.url"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button size="small"
                       type="primary"
                       @click="saveModule('form')">保存</el-button>
            <el-button size="small"
                       type="primary"
                       v-show="showdelete"
                       @click="deleteModule">删除</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  ModuleList,
  ModuleGet,
  ModuleNodes,
  ModuleSave,
  ModuleDelete,
} from '../../api/userMG'
import treeMenu from '@/components/treeMenu'
export default {
  components: {
    treeMenu,
  },
  data() {
    return {
      showdelete: false,
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'name',
      },
      isalert: true,
      form: {
        menuid: '',
        menuname: '',
        icon: '',
        url: '',
        addUser: '',
        editUser: '',
        addTime: '',
        editTime: '',
        moduleId: '',
        parentId: '',
        moduleLevel: '',
        systemNo: '',
        isLeaf: '',
        fullIndex: '',
        moduleIcon: '',
        moduleOrder: '',
        moduleName: '',
        moduleNotes: '',
        moduleUrl: '',
      },
      // rules表单验证
      rules: {
        menuid: [
          { required: true, message: '请选择父级菜单', trigger: 'blur' },
        ],
        menuname: [
          { required: true, message: '请输入菜单名称', trigger: 'blur' },
        ],
        icon: [{ required: true, message: '请输入菜单图标', trigger: 'blur' }],
        url: [{ required: true, message: '请输入URL', trigger: 'blur' }],
      },
      fmenu: [],
    }
  },
  /**
   * 创建完毕
   */

  created() {
    this.getmenu()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    callfather(data) {
      this.form.menuid = data.menuid
      this.form.menuname = data.menuname
      this.form.icon = data.icon
      this.form.url = data.url
    },
    // 获取数据

    // 保存菜单
    saveModule(editData) {
      this.$refs[editData].validate((valid) => {
        if (valid) {
          // ModuleSave(this.form)
          this.$axios
            .post('/api/menus/updateMenus/', this.form)
            .then((res) => {
              console.log(res)
              if (res.data.code == 200) {
                this.$message.info(res.data.msg)
                this.isalert = !this.isalert
              }
            })
            .catch((err) => {
              this.$message.error('菜单管理列表保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除菜单
    deleteModule() {
      ModuleDelete(this.form.moduleId)
        .then((res) => {
          this.getmenu()
          this.$message.error('菜单管理列表删除成功！')
        })
        .catch((err) => {
          this.$message.error('菜单管理列表删除失败，请稍后再试！')
        })
    },
  },
}
</script>

<style>
.user-search {
  margin-top: 20px !important;
}
.user-search td {
  margin-top: 20px !important;
}
.userRole {
  width: 100%;
}
.el-table__expanded-cell {
  padding: 0px !important;
  margin: 0px !important;
}
.modt-box {
  width: 100%;
  height: 60px;
  line-height: 60px;
  background-color: #f0f2f5;
  text-align: center;
  color: #334157;
  margin-top: 20px;
  margin-bottom: 20px;
  font-size: 24px;
}
.mod-btnbox {
  margin-bottom: 20px;
}
.treeclass {
  border: 1px solid #f3f3f3;
  padding-top: 20px;
  padding-bottom: 20px;
}
.selectw {
  width: 100%;
}
</style>
 
 